package service.dept.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import dao.dept.DeptManageDao;
import entities.organization.Dept;
import service.dept.DeptManageService;
/**
 * 部门管理
 * @author hxl
 *
 */
@Service
@Transactional
public class DeptManageServiceImpl implements DeptManageService {
	@Resource(name="transactionManager")
	private DataSourceTransactionManager transactionManager;
    @Resource
    private DeptManageDao deptManageDao;
	@Override
	public List<Dept> getDepts() {
		
		
		DefaultTransactionDefinition def = new DefaultTransactionDefinition();
		def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别，开启新事务，这样会比较安全些。
		TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
		try {
			//逻辑代码，可以写上你的逻辑处理代码
			transactionManager.commit(status);
		} catch (Exception e) {
			transactionManager.rollback(status);
		}
		return deptManageDao.getDepts();
	}

}
